package com.ruoyi.teach.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import com.ruoyi.teach.domain.TeachPlan;
import com.ruoyi.teach.service.ITeachPlanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 教案Controller
 * 
 * @author yepanpan
 * @date 2021-03-15
 */
@Api("教案管理")
@RestController
@RequestMapping("/teach/plan")
public class TeachPlanController extends BaseController
{
    @Autowired
    private ITeachPlanService teachPlanService;

    /**
     * 查询教案列表
     */
    @ApiOperation("查询教案列表")   
    @GetMapping("/my")
    public TableDataInfo my(TeachPlan teachPlan)
    {
        startPage();
        List<TeachPlan> list = teachPlanService.selectTeachPlanList(teachPlan);
        return getDataTable(list);
    }

    /**
     * 查询教案列表
     */
    @ApiOperation("查询教案列表")   
    @PreAuthorize("@ss.hasPermi('teach:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeachPlan teachPlan)
    {
        startPage();
        List<TeachPlan> list = teachPlanService.selectTeachPlanList(teachPlan);
        return getDataTable(list);
    }

    /**
     * 导出教案列表
     */
    @ApiOperation("导出教案列表")    
    @PreAuthorize("@ss.hasPermi('teach:plan:export')")
    @Log(title = "教案", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TeachPlan teachPlan)
    {
        List<TeachPlan> list = teachPlanService.selectTeachPlanList(teachPlan);
        ExcelUtil<TeachPlan> util = new ExcelUtil<TeachPlan>(TeachPlan.class);
        return util.exportExcel(list, "plan");
    }

    /**
     * 获取教案详细信息
     */
    @ApiOperation("获取教案详细信息")
    @ApiImplicitParam(name = "id", value = "教案ID", required = true, dataType = "int", paramType = "path") 
    @PreAuthorize("@ss.hasPermi('teach:plan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(teachPlanService.selectTeachPlanById(id));
    }

    /**
     * 新增教案
     */
    @ApiOperation("新增教案")
    @PreAuthorize("@ss.hasPermi('teach:plan:add')")
    @Log(title = "教案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeachPlan teachPlan)
    {
        return toAjax(teachPlanService.insertTeachPlan(teachPlan));
    }

    /**
     * 修改教案
     */
    @ApiOperation("修改教案")  
    @PreAuthorize("@ss.hasPermi('teach:plan:edit')")
    @Log(title = "教案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeachPlan teachPlan)
    {
        return toAjax(teachPlanService.updateTeachPlan(teachPlan));
    }

    /**
     * 删除教案
     */
    @ApiOperation("删除教案")
    @ApiImplicitParam(name = "id", value = "教案ID", required = true, dataType = "int", paramType = "path") 
    @PreAuthorize("@ss.hasPermi('teach:plan:remove')")
    @Log(title = "教案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(teachPlanService.deleteTeachPlanByIds(ids));
    }
}
